using UnityEngine;
using System.Collections;
using System.IO;

public class Create_Profile : MonoBehaviour
{

    int id = 1;
    GameObject fade_in;
    GameObject fade_out;
    GameObject button;

    StreamWriter stream_writer;
    StreamReader stream_reader;

    float count_change_scene;

    void Start()
    {
        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");


        Mesh mesh = Quad.Create(4.0f, 3.0f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};

        fade_in = new GameObject("Fade_In", typeof(Fade_In));
        Fade_Out.fade_out_begin = false;
        Fade_Out.fade_out_terminated = false;
    }

    void Update()
    {
    	if (Fade_Out.fade_out_terminated)
    	{
			Application.LoadLevel("Game");
		}
    }

	string tf_name = "Digite aqui seu nome...";

    void OnGUI()
    {
		GUI.Label(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 15 - 150, 160, 30), "Escolha a dificuldade:");

		GUI.Label(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 15 - 80, 160, 30), "Money:" + Player.money);

		tf_name = GUI.TextField(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 15, 200, 30), tf_name);

        if (GUI.Button(new Rect(Screen.width / 2 - 40 - 90, Screen.height / 2 - 15 - 120, 80, 30), "Easy"))
        {
			Player.money = 20000;
        }

		if (GUI.Button(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 15 - 120, 80, 30), "Medium"))
        {
			Player.money = 10000;
        }

        if (GUI.Button(new Rect(Screen.width / 2 - 40 + 90, Screen.height / 2 - 15 - 120, 80, 30), "Hard"))
        {
			Player.money = 5000;
        }

		if (GUI.Button(new Rect(Screen.width / 2 - 40, Screen.height / 2 - 15 + 80, 80, 30), "Iniciar"))
		{
			Player.olimpcoins = 500;

			Player.name = tf_name;

			Database.Create_Profile();

			if (!Fade_Out.fade_out_begin)
			{
				fade_out = new GameObject("Fade_Out", typeof(Fade_Out));
			}
		}
	}
}
